package cn.itcast.mobilebrowser.viewmodel;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import java.util.ArrayList;
import java.util.List;

import cn.itcast.mobilebrowser.model.WebTab;


/**
 * 标签页的数据
 */
public class WebTabViewModel extends ViewModel {

    // 标签页的list
    private List<WebTab> list = new ArrayList<>();

    private final MutableLiveData<List<WebTab>> mutableLiveData = new MutableLiveData<>(list);

    // 当前的标签
    private final MutableLiveData<WebTab> currentTab = new MutableLiveData<>();

    public LiveData<List<WebTab>> getMutableLiveData() {
        return this.mutableLiveData;
    }

    public LiveData<WebTab> getCurrentTab() {
        return this.currentTab;
    }

    public void setCurrentTab(WebTab webTab) {
        currentTab.setValue(webTab);
    }

    public void addTab(WebTab webTab) {
        list.add(webTab);
        mutableLiveData.setValue(list);
    }

    public void addTab(WebTab webTab, int position) {
        list.add(position, webTab);
        mutableLiveData.setValue(list);
    }

    public void deleteTab(int position) {
        list.remove(position);
        mutableLiveData.setValue(list);
    }

    public void setTabs(List<WebTab> list) {
        this.list = list;
        mutableLiveData.setValue(list);
    }

    public List<WebTab> getTabs() {
        return this.list;
    }
}
